package cn.itcast.itcaststore.web.servlet;

import cn.itcast.itcaststore.service.Impl.IOrderService;
import cn.itcast.itcaststore.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/ShowOrdersServlet")
public class ShowOrdersServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String type = (String) request.getAttribute("type");

        Long by = null;
        if (type=="id"){
            by = (Long) request.getAttribute("order_id");
        }

        OrderService orderService=new IOrderService();
        ArrayList list=orderService.getTypeOrders(type,by);

        request.setAttribute("list",list );
        request.getRequestDispatcher("/client/orderInfo.jsp").forward(request,response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
